package br.odonto.entities;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.ForeignKey;

import br.odonto.controle.TipoUsuario;

@ManagedBean(name="usuario")
@RequestScoped
@Entity
@Table(name="usuario")
public class Usuario{
	@Id
	@GeneratedValue
	private int id;
	@Column(length=20,nullable=false)
	private String login;
	@Column(length=20,nullable=false)
	private String senha;
	@OneToOne(targetEntity=TipoUsuario.class)
	@ForeignKey(name="FK_tipo_usuario")
	@Cascade(CascadeType.ALL)
	private TipoUsuario permissao;
	@OneToOne(targetEntity=Pessoa.class)
	@ForeignKey(name="FK_pessoa_usuario")
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinColumn(name="")
	private Pessoa pessoa;
	
	public static Usuario instance;
	public Usuario() {
		// TODO Auto-generated constructor stub
	}	

	public Pessoa getPessoa() {
		return pessoa;
	}



	public void setPessoa(Pessoa pessoa) {
		this.pessoa = pessoa;
	}



	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getSenha() {
		return senha;
	}
	public void setSenha(String senha) {
		this.senha = senha;
	}



	public TipoUsuario getPermissao() {
		return permissao;
	}



	public void setPermissao(TipoUsuario permissao) {
		this.permissao = permissao;
	}
	
	
	
}
